import {message} from 'antd';
import {formatMessage} from './intl';
import {isEmptyOrNull} from './utils';

export const updateValidator = condition => {
    if(
        condition.dealerParts.some(
            item =>
                isEmptyOrNull(item.brandId) ||
                isEmptyOrNull(item.tradeMethodId) ||
                isEmptyOrNull(item.arrivedDealerId) ||
                isEmptyOrNull(item.priceClause) ||
                isEmptyOrNull(item.isSeparate) ||
                isEmptyOrNull(item.currency) ||
                isEmptyOrNull(item.isPlaned) ||
                isEmptyOrNull(item.isClaim) ||
                (item.isPlaned === true && (isEmptyOrNull(item.planedStartDate) || isEmptyOrNull(item.planedEndDate)))
        )
    ) {
        message.warn(
            formatMessage({
                id: 'validate.partInformation.detailFieldRequired',
                defaultMessage: '存在总代备件业务信息清单的必填项为空'
            })
        );
        return false;
    }
    return true;
};
